package erp_services

import (
	"errors"
	"time"
	"xiehui-service/app/models/erp_models"
	"xiehui-service/global"
)

type orderAtuoDispatchLogService struct {
}

var OrderAtuoDispatchLogService = new(orderAtuoDispatchLogService)

func (orderAtuoDispatchLogService *orderAtuoDispatchLogService) CreateLog(op_desc string, op_content string, start_time time.Time) (err error) {
	opLog := erp_models.OrderAutoDispatchLog{
		OperatorDesc:    op_desc,
		OperatorContent: op_content,
		StartTime:       start_time,
	}
	err = global.App.DB.Create(&opLog).Error
	if err != nil {
		err = errors.New("数据创建失败")
	}

	return
}

// 获取操作日志
func (orderAtuoDispatchLogService *orderAtuoDispatchLogService) GetLog(pageNum, pageSize int) (orderAutoDispatchLog []erp_models.OrderAutoDispatchLog, err error) {
	err = global.App.DB.Order("id DESC").Offset((pageNum - 1) * pageSize).Limit(pageSize).Find(&orderAutoDispatchLog).Error
	if err != nil {
		err = errors.New("查询日志数据失败")
	}
	return
}
